<template>
  <tree-select
    ref="treeSelect"
    @treeSelect="handleTreeSelect"
    :selectStyle="selectStyle"
    :options="selectData"
    :selectValue="selectValue"
    :disabled="disabled"
  />
</template>

<script>
import TreeSelect from '@/components/ETreeSelect'
import { queryUserList } from '@/api/assetsNew'

export default {
  components: {
    TreeSelect
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    selectValue: {
      type: String,
      default: ''
    },
    selectStyle: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  watch: {
    selectValue(n, o) {
      // console.log('selectValue', n, o)
      this.value = n
    }
  },
  data() {
    return {
      selectData: [],
      value: this.selectValue
    }
  },
  mounted() {
    queryUserList().then(res => {
      if (res.data.length > 0) {
        this.selectData = res.data
        this.selectData.map(v => {
          v.id = v.value
          v.label = v.title
        })
      }
    })
  },
  methods: {
    reset() {
      this.$refs.treeSelect.reset()
    },
    handleTreeSelect(value) {
      // console.log('value', value)
      this.$emit('select', value)
    }
  }
}
</script>
